import Config from './../config/config';

const mysql = require("mysql");

const conn = mysql.createConnection({
    host: Config.mysql.host,
    user:  Config.mysql.user,
    password: Config.mysql.pwd,
    database: Config.mysql.database
});

const db = {};

db.query = function(sql){
    console.log(sql);    
    return new Promise(function(resolve,reject){        
        conn.query(sql, function(err, rows, fields) {
            if (err) throw err; 
            let data = JSON.parse(JSON.stringify(rows));                    
            resolve(data);
        });
    });
}
db.close = function(){
    conn.end();
}
export default db;


